package com.beiing.tianshuai.tianshuai.huodong.presenter;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.ActiveReplyBean;
import com.beiing.tianshuai.tianshuai.entity.BaseBean;
import com.beiing.tianshuai.tianshuai.entity.CodeBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDeleteBean;
import com.beiing.tianshuai.tianshuai.entity.FollowBean;
import com.beiing.tianshuai.tianshuai.entity.FollowResultBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongCollectBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongCommentBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongDetailBean;
import com.beiing.tianshuai.tianshuai.entity.HuoDongPraiseBean;
import com.beiing.tianshuai.tianshuai.huodong.model.HuoDongDetailModel;
import com.beiing.tianshuai.tianshuai.huodong.model.HuoDongDetailModelImpl;
import com.beiing.tianshuai.tianshuai.huodong.view.HuoDongDetailViewImpl;
import com.beiing.tianshuai.tianshuai.util.LogUtils;

/**
 * Created by magikliu on 2017/8/6.
 */

public class HuoDongDetailPresenter implements HuoDongDetailPresenterImpl {

    private HuoDongDetailModelImpl mModel;
    private HuoDongDetailViewImpl mView;

    public HuoDongDetailPresenter(HuoDongDetailViewImpl mView) {
        this.mView = mView;
        this.mModel = new HuoDongDetailModel();
    }

    @Override
    public void getHuoDongDetail(String uid, String id) {
        mModel.getHuoDongDetail(uid, id, new CallBack<HuoDongDetailBean>() {

            @Override
            public void result(HuoDongDetailBean bean) {
                mView.showCommentList(bean.getData().getComment());
                mView.showHuoDongDetail(bean.getData());
            }

            @Override
            public void error(Throwable e) {
                LogUtils.e(e.getMessage(), "get activity details error");
                mView.firstLoadError(e);
            }
        });
    }

    @Override
    public void collectHuoDong(final String uid, final String aid) {
        mModel.collectHuoDong(uid, aid, new CallBack<HuoDongCollectBean>() {
            @Override
            public void result(HuoDongCollectBean bean) {
//                getHuoDongDetail(uid, aid);
                mView.shoeActiveCollectResult(bean);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void commentHuoDong(String aid, final String uid, final String content, final String add_time) {
        mModel.commentHuoDong(aid, uid, content, add_time, new CallBack<HuoDongCommentBean>() {

            @Override
            public void result(HuoDongCommentBean bean) {
                mView.submitCommentFinish(bean, content, add_time);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void attentionUser(String form_uid, String to_uid) {
        mModel.attentionUser(form_uid, to_uid, new CallBack<FollowResultBean>() {

            @Override
            public void result(FollowResultBean bean) {

            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void isFollowed(String fromUid, String toUid) {
        mModel.isFollowed(fromUid, toUid, new CallBack<FollowBean>() {

            @Override
            public void result(FollowBean bean) {
                mView.showFollowed(bean);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void setFollowed(final String fromUid, final String toUid) {
        mModel.setFollowed(fromUid, toUid, new CallBack<FollowResultBean>() {

            @Override
            public void result(FollowResultBean bean) {
                isFollowed(fromUid, toUid);
                if (bean.getCode() == 204){
                    mView.showToast("取消关注成功!");
                } else {
                    mView.showToast("关注成功！");
                }
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void praiseHuoDong(final String userid, final String aid) {
        mModel.praiseHuoDong(userid, aid, new CallBack<HuoDongPraiseBean>() {

            @Override
            public void result(HuoDongPraiseBean bean) {
                mView.showPraised(bean);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void praiseComment(final String uid, final String aid, String cid, final int position) {
        mModel.praiseComment(uid, cid, new CallBack<HuoDongPraiseBean>() {

            @Override
            public void result(HuoDongPraiseBean bean) {
                mView.showPraiseCommentResult(bean, position);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void deleteComment(String id) {
        mModel.deleteComment(id, new CallBack<CodeBean>() {

            @Override
            public void result(CodeBean bean) {

            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void addReply(String aid, String cid, String form_id, String to_id, final String content, String comment, int type, String rid) {
        mModel.addReply(aid, cid, form_id, to_id, content, comment, type, rid, new CallBack<ActiveReplyBean>() {

            @Override
            public void result(ActiveReplyBean bean) {
                mView.addReply(bean, content);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void deleteReply(String aid, String id, String uid) {
        mModel.deleteReply(aid, id, uid, new CallBack<DynamicDeleteBean>() {

            @Override
            public void result(DynamicDeleteBean bean) {

            }

            @Override
            public void error(Throwable e) {

            }
        });
    }

    @Override
    public void praiseReply(String uid, String aid, String cid, String rid, String to_uid, final int position) {
        mModel.praiseReply(uid, aid, cid, rid, to_uid, new CallBack<HuoDongPraiseBean>() {

            @Override
            public void result(HuoDongPraiseBean bean) {
                mView.showPraiseCommentResult(bean, position);
            }

            @Override
            public void error(Throwable e) {

            }
        });
    }
}
